package com.ruoyi.hr.service.impl.welfare.welfareRegion;

import com.ruoyi.common.annotation.DataSource;
import com.ruoyi.common.enums.DataSourceType;
import com.ruoyi.hr.domain.welfare.welfareregion.WelfareRegionConfig;
import com.ruoyi.hr.mapper.welfare.welfareRegion.WelfareRegionConfigMapper;
import com.ruoyi.hr.service.welfare.welfareRegion.WelfareRegionConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class WelfareRegionConfigServiceImpl implements WelfareRegionConfigService {
    @Autowired
    WelfareRegionConfigMapper welfareRegionConfigMapper;

    @DataSource(value = DataSourceType.SLAVE)
    @Override
    public List<WelfareRegionConfig> findAll(Map map) {
        return welfareRegionConfigMapper.findAll(map);
    }

    @DataSource(value = DataSourceType.SLAVE)
    @Override
    public int findCount(WelfareRegionConfig welfareRegionConfig) {
        return welfareRegionConfigMapper.findCount(welfareRegionConfig);
    }

    @DataSource(value = DataSourceType.SLAVE)
    @Override
    public int updateIsDisabled(WelfareRegionConfig welfareRegionConfig) {
        return welfareRegionConfigMapper.updateIsDisabled(welfareRegionConfig);
    }

    @DataSource(value = DataSourceType.SLAVE)
    @Override
    public int updateDefault(WelfareRegionConfig welfareRegionConfig) {
        return welfareRegionConfigMapper.updateDefault(welfareRegionConfig);
    }

    @DataSource(value = DataSourceType.SLAVE)
    @Override
    public int insertWelfareRegionConfig(WelfareRegionConfig welfareRegionConfig) {
        return welfareRegionConfigMapper.insertWelfareRegionConfig(welfareRegionConfig);
    }

    @DataSource(value = DataSourceType.SLAVE)
    @Override
    public WelfareRegionConfig findWelfareRegionConfigById(int id) {
        return welfareRegionConfigMapper.findWelfareRegionConfigById(id);
    }

    @DataSource(value = DataSourceType.SLAVE)
    @Override
    public int updateWelfareRegionConfig(WelfareRegionConfig welfareRegionConfig) {
        return welfareRegionConfigMapper.updateWelfareRegionConfig(welfareRegionConfig);
    }

    @DataSource(value = DataSourceType.SLAVE)
    @Override
    public int deleteWelfareRegionConfig(String ids) {
        int num = 0;
        if (ids.indexOf(",") != -1) {
            String[] arry = ids.split("\\,");
            for (String id : arry) {
                num += welfareRegionConfigMapper.deleteWelfareRegionConfig(id);
            }
        } else {
            num = welfareRegionConfigMapper.deleteWelfareRegionConfig(ids);
        }
        return num;
    }

    @DataSource(value = DataSourceType.SLAVE)
    @Override
    public List<WelfareRegionConfig> findAlla() {
        return welfareRegionConfigMapper.findAlla();
    }
}
